﻿@inject INotificationService _notice

<Button Type="@ButtonType.Primary" OnClick="@OnClick">
    Open the notification box
</Button>

@code{
    private async Task OnClick()
    {
        var config = new NotificationConfig()
        {
            // disable auto remove
            Duration = 0,
            Message = "title",
            Description = "This is the content of the notification. This is the content of the notification. This is the content of the notification."
        };

        var notificationRef = await _notice.CreateRefAsync(config);
        // create a notificationRef and open the notification box
        // var notificationRef = await _notice.Open(config);


        // only trigger in NotificationRef.OpenAsync()
        notificationRef.OnOpen = () =>
        {
            Console.WriteLine("notificationRef.OnOpen");
            return Task.CompletedTask;
        };

        // only trigger in NotificationRef.CloseAsync()
        notificationRef.OnClose = () =>
        {
            Console.WriteLine("notificationRef.OnClose");
            return Task.CompletedTask;
        };


        // open the notification box
        await notificationRef.OpenAsync();
        await Task.Delay(TimeSpan.FromSeconds(2));


        // update notification box's description
        config.Description = "new description";
        await notificationRef.UpdateConfigAsync();
        // override
        // await notificationRef.UpdateConfigAsync("new description");
        // await notificationRef.UpdateConfigAsync("new description", "new message");


        await Task.Delay(TimeSpan.FromSeconds(2));
        // close the notification box
        await notificationRef.CloseAsync();
    }
}